package com.zyf.school.manager.controller;

import com.alibaba.fastjson.JSONObject;
import com.zyf.school.manager.domain.Dict;
import com.zyf.school.manager.service.DictService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@Controller
@RequestMapping("/dict/")
public class DictController {
    @Autowired
    private DictService dictService;

    private List<Dict> dictList;
    private Dict dict;

    //基础参数设置
    @RequestMapping("param")
    public String param(HttpServletRequest request){
        dictList = dictService.queryAll(0,5);
        request.setAttribute("dictList",dictList);
        return "/dict/param";
    }
    @RequestMapping(value = "ajaxQuery",method = RequestMethod.POST)
    @ResponseBody
    public JSONObject ajaxQuery(HttpServletResponse response){
        response.setHeader("Access-Control-Allow-Origin", "*");
        response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE");
        response.setHeader("Access-Control-Max-Age", "3600");
        response.setHeader("Access-Control-Allow-Headers", "x-requested-with");
        dictList = dictService.queryAll(0,5);
        JSONObject obj = new JSONObject();
        obj.put("title","测试中......");
        return obj;
    }
}
